cd E:\data\cooperation\poor\gini
****************original data************************
use da_original,clear  
egen idd = group(id)
xtset idd year
gen vdem_egaldem_2=vdem_egaldem^2
gen l_wdi_gdp=ln(wdi_gdpcapcon2010)
gen l_wdi_fdiin=ln(wdi_fdiin)
gen l_unna_pop=ln(unna_pop)
gen l_wdi_area=ln(wdi_area)
gen l_wdi_refori=ln(wdi_refori)
/*year and country*/
label var year "Year"
label var id "country code"
label var pov9	"Gini Index"
label var vdem_egaldem "Egalitarian democracy index"
label var l_unna_pop "The log of population"
label var wdi_lfpf "Labor force, female (% of total labor force)"
label var dr_sg "social globalization"
label var wdi_araland "Arable land (% of land area)"
label var wdi_agedr "Age dependency ratio (% of working-age population)"
label var wdi_tele "Fixed telephone subscriptions (per 100 people)"
label var wdi_poprul "Rural population (% of total population)"
label var wdi_internet "Individuals using the Internet (% of population)"
label var wdi_unempfilo "Unemployment, female (% of female labor force)"
label var l_wdi_gdp	"The log of GDP per Capital"
label var p_durable	"Regime Durability"
label var ht_colonial	"Colonial Origin"
label var dpi_system	"Political System"
label var l_wdi_fdiin	"The log of Foreign direct investment, net inflows (% of GDP)" 
label var l_wdi_refori "Refugee population by country or territory of origin"
label var wdi_popden "Population density (people per sq. km of land area)"





keep id idd year pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ht_colonial dpi_system 

des pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ht_colonial dpi_system 
******************************************************************
 sum pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ht_colonial dpi_system 

collin vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori 

xtunitroot fisher pov9, pperron lags(2) 

 xtreg l(0/1).pov9 vdem_egaldem,fe 
 est store fe
 xtreg l(0/1).pov9 vdem_egaldem,re 
 est store re
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori ,fe
 est store fe1
 hausman  fe re
 xtreg l(0/1).pov9 vdem_egaldem vdem_egaldem_2 l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,fe
 est store fe2
 xtreg l(0/1).pov9 vdem_egaldem  l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable l_wdi_fdiin wdi_poprul l_wdi_refori  i.year ,fe
 est store fe3
  xtivreg2 l(0/1).pov9 (vdem_egaldem= vdem_polyarchy p_polity2 vdem_libdem) l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin ,fe
est store iv3
 esttab fe re fe1 fe2 fe3 iv3, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE" "FE" "FE" "FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 4*/
 

 **********panel B**********
 use da_rolling,clear  
egen idd = group(id)
egen y=group(year)
xtset idd year
gen vdem_egaldem_2=vdem_egaldem^2
gen l_wdi_gdp=ln(wdi_gdpcapcon2010)
gen l_wdi_fdiin=ln(wdi_fdiin)
gen l_imf_infl=ln(imf_infl)
gen l_unna_pop=ln(unna_pop)
gen l_wdi_area=ln(wdi_area)
gen l_wdi_refori=ln(wdi_refori)
label var year "Year"
label var id "country code"
label var pov9	"Gini Index"
label var vdem_egaldem "Egalitarian democracy index"
label var l_unna_pop "The log of population"
label var wdi_lfpf "Labor force, female (% of total labor force)"
label var dr_sg "social globalization"
label var wdi_araland "Arable land (% of land area)"
label var wdi_agedr "Age dependency ratio (% of working-age population)"
label var wdi_tele "Fixed telephone subscriptions (per 100 people)"
label var wdi_poprul "Rural population (% of total population)"
label var wdi_internet "Individuals using the Internet (% of population)"
label var wdi_unempfilo "Unemployment, female (% of female labor force)"
label var l_wdi_gdp	"The log of GDP per Capital"
label var p_durable	"Regime Durability"
label var ht_colonial	"Colonial Origin"
label var dpi_system	"Political System"
label var l_wdi_fdiin	"The log of Foreign direct investment, net inflows (% of GDP)" 
label var l_wdi_refori "Refugee population by country or territory of origin"
label var wdi_popden "Population density (people per sq. km of land area)"
sum pov9 

collin vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori 

xtunitroot fisher pov9,pperron lags(2) 

 xtreg pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year
 est store ols
 xtreg l(0/1).pov9 vdem_egaldem,fe
 est store fe
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori ,fe
 est store fe1
 xtreg l(0/1).pov9  vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  ,re
 est store re
 hausman fe re
 xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori  i.year ,fe
 est store fe3
 esttab fe ols fe1  fe3, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE" "OLS" "FE" "FE" "FE" ) /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 5*/ 
 
 ***********deep analysis****************
preserve
keep if ht_colonial==0
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden ,fe
est store f
 esttab f, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  
restore

preserve
keep if ht_colonial==1
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden ,fe
est store f
 esttab f, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  
restore
 
gen colonial_vem=ht_colonial*vdem_egaldem
 
xtreg l(0/1).pov9 vdem_egaldem  colonial_vem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden,fe
 est store inf
 esttab inf, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE"  ) /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  /*table 3*/ 
 
preserve
keep if dpi_system==0
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden ,fe
est store f
 esttab f, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  
restore

preserve
keep if dpi_system==1
xtreg l(0/1).pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden ,fe
est store f
 esttab f, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared ))  
restore
 
gen system_vem=dpi_system*vdem_egaldem
 
xtreg l(0/1).pov9 vdem_egaldem dpi_system system_vem l_unna_pop  wdi_lfpf wdi_araland wdi_agedr l_wdi_gdp wdi_unempfilo wdi_internet  wdi_tele ///
dr_sg p_durable  l_wdi_fdiin wdi_poprul l_wdi_refori wdi_popden,fe
est store inef
esttab inef, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("FE") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) 
 
 
 xtdpdsys pov9 vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland , lags(1) twostep  artests(2)
 est store dpd
predict res, e
xtcd2 res
xtabond2 L(0/1).pov9 vdem_egaldem l_unna_pop wdi_lfpf wdi_araland, ///
gmm(L.pov9 vdem_egaldem l_unna_pop wdi_lfpf wdi_araland)  robust twostep small h(2) 

xtcd2 
est store gmm
 xtdcce2 d.pov9 d.vdem_egaldem   ,lr( ///
   l_unna_pop wdi_lfpf wdi_araland  ) p(L.pov9  l_unna_pop  wdi_lfpf wdi_araland  ) ///
  cr(d.pov9 d.vdem_egaldem l_unna_pop  wdi_lfpf wdi_araland  ) nocross lr_options(xtpmgnames) 
est store cce3
esttab dpd gmm cce3, cells(b(star fmt(4)) se(par fmt(2))) /// 
legend label  varwidth(50) varlabels(_cons constant) mtitles("DPD" " " " ") /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) 
 